home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions BackFullSynapse component
-
- #include "NSDLL.h"
-
- /*************************************************************/
- /* Macros to access the PE layers and weights in matrix form */
-
- #define in(i,j) errorIn[j+i*inCols]
- #define out(i,j) errorOut[j+i*outCols]
- #define W(i,j) weights[j+i*outCount]
- #define Wg(i,j) gradients[j+i*outCount]
-
- /********************************/
- /* Backpropagation of component */
-
- __declspec(dllexport) void performBackFullSynapse(
- DLLData *instance, // Pointer to instance data (may be NULL)
- DLLData *dualInstance, // Pointer to the forward synapses instance data (may be NULL)
- NSFloat *errorIn, // Pointer to the input error layer of processing elements (PEs)
- int inRows, // Number of rows of PEs in the input layer (don't forget that input and output are reversed)
- int inCols, // Number of columns of PEs in the input layer
- NSFloat *errorOut, // Pointer to the output error layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols, // Number of columns of PEs in the output layer
- NSFloat *input, // Pointer to the output layer of the forward synapse
- NSFloat *weights, // Pointer to the fully connected matrix of weights
- NSFloat *gradients // Pointer to the weight gradient matrix
- )
- {
- int i, j,
- inCount=inRows*inCols,
- outCount=outRows*outCols;
-
- for (i=0; i<outCount; i++)
- for (j=0; j<inCount; j++) {
- errorOut[i] += W(j,i)*errorIn[j];
- if (gradients)
- Wg(j,i) += errorIn[j]*input[i];
- }
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocBackFullSynapse(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- DLLData *dualInstance, // Pointer to forward axonÆs instance data (may be NULL)
- int inRows, // Number of rows of PEs in the input layer
- int inCols, // Number of columns of PEs in the input layer
- int outRows, // Number of rows of PEs in the output layer
- int outCols // Number of columns of PEs in the output layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeBackFullSynapse(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */